import request from "@/utils/request";
import {BaseResponse} from "@/api/types/baseResponse";
import {DeliveryPointRequest, DeliveryPointResponse} from "@/api/types/deliveryPoint";

// 公用的 API 地址
const URL = "/system/peisongdian"

// 查询所有的配送点
export async function getDeliveryPoints() {
    // return await request.get<BaseResponse<DeliveryPointResponse[]>, BaseResponse<DeliveryPointResponse[]>>(URL)
    return await request<BaseResponse<DeliveryPointResponse[]>, BaseResponse<DeliveryPointResponse[]>>({
        url:'/system/getpsd',
        method:'get',
    })
}

// 根据 ID 查询配送点
export async function getDeliveryPointById(id: number) {
    return await request.get<BaseResponse<DeliveryPointResponse[]>, BaseResponse<DeliveryPointResponse[]>>(URL, {params: {id}})
}

// 增加配送点
export async function addDeliveryPoint(data: DeliveryPointRequest) {
    return await request.post<BaseResponse<[]>, BaseResponse<[]>>(URL, data)
}

// 修改配送点
export async function updateDeliveryPoint(data: DeliveryPointRequest) {
    return await request.put<BaseResponse<string>, BaseResponse<string>>(URL, data)
}

// 根据 ID 删除配送点
export async function deleteDeliveryPointById(id: number) {
    return await request.delete<BaseResponse<boolean>, BaseResponse<boolean>>(URL, {data: {id}})
}
